package cn.youqu.happy.module.youqu.dal.mysql.arrangeEdit;

import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.framework.mybatis.core.mapper.BaseMapperX;
import cn.youqu.happy.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.youqu.happy.module.youqu.controller.admin.arrangeEdit.vo.ArrangeEditExportReqVO;
import cn.youqu.happy.module.youqu.controller.admin.arrangeEdit.vo.ArrangeEditPageReqVO;
import cn.youqu.happy.module.youqu.dal.dataobject.arrangeEdit.ArrangeEditDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 计划申请修改 Mapper
 *
 * @author 王其岩 20112001045
 */
@Mapper
public interface ArrangeEditMapper extends BaseMapperX<ArrangeEditDO> {
    ArrangeEditDO findOneByIdAndApplyUid(@Param("id") Integer id, @Param("applyUid") Long applyUid);

    int updateApplyStatusAndRemarkById(@Param("updatedApplyStatus") Integer updatedApplyStatus, @Param("updatedRemark") String updatedRemark, @Param("id") Integer id);

    Integer countByArrangeId(@Param("arrangeId") Integer arrangeId);

    Integer countByArrangeIdAndApplyStatus(@Param("arrangeId") Integer arrangeId, @Param("applyStatus") Integer applyStatus);


    default PageResult<ArrangeEditDO> selectPage(ArrangeEditPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ArrangeEditDO>()
                .eqIfPresent(ArrangeEditDO::getArrangeId, reqVO.getArrangeId())
                .eqIfPresent(ArrangeEditDO::getApplyUid, reqVO.getApplyUid())
                .eqIfPresent(ArrangeEditDO::getApplyStatus, reqVO.getApplyStatus())
                .eqIfPresent(ArrangeEditDO::getApplyType, reqVO.getApplyType())
                .eqIfPresent(ArrangeEditDO::getAgreeIds, reqVO.getAgreeIds())
                .eqIfPresent(ArrangeEditDO::getRefuseIds, reqVO.getRefuseIds())
                .betweenIfPresent(ArrangeEditDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(ArrangeEditDO::getRemark, reqVO.getRemark())
                .orderByDesc(ArrangeEditDO::getId));
    }

    default List<ArrangeEditDO> selectList(ArrangeEditExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ArrangeEditDO>()
                .eqIfPresent(ArrangeEditDO::getArrangeId, reqVO.getArrangeId())
                .eqIfPresent(ArrangeEditDO::getApplyUid, reqVO.getApplyUid())
                .eqIfPresent(ArrangeEditDO::getApplyStatus, reqVO.getApplyStatus())
                .eqIfPresent(ArrangeEditDO::getApplyType, reqVO.getApplyType())
                .eqIfPresent(ArrangeEditDO::getAgreeIds, reqVO.getAgreeIds())
                .eqIfPresent(ArrangeEditDO::getRefuseIds, reqVO.getRefuseIds())
                .betweenIfPresent(ArrangeEditDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(ArrangeEditDO::getRemark, reqVO.getRemark())
                .orderByDesc(ArrangeEditDO::getId));
    }

}
